package com.ruoyi.web.controller.mobile;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.mobile.model.vo.MessageInfoVo;
import com.ruoyi.mobile.model.vo.MessageVo;
import com.ruoyi.mobile.service.IMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/message")
public class MessageController extends BaseController {

    @Autowired
    public IMessageService messageService;


    @GetMapping("/info")
    public AjaxResult info(@RequestParam(name = "userId", defaultValue = "0") int userId, @RequestParam(name = "page", defaultValue = "1") int page, @RequestParam(name = "lastId", defaultValue = "0") int lastId) {
        if (userId <= 0) {
            throw new ServiceException("不存在的客服");
        }
        LoginUser loginUser = getLoginUser();
        Integer doctorId = loginUser.getUserId().intValue();
        MessageInfoVo messageInfoVo = messageService.getMessageInfo(userId, doctorId, page, lastId);

        return AjaxResult.success(messageInfoVo);
    }

    @GetMapping("/list")
    public AjaxResult list(@RequestParam(name = "page", defaultValue = "1") int page) {
        LoginUser loginUser = getLoginUser();
        List<MessageVo> list = messageService.getMessageList(loginUser.getUserId().intValue(), page);
        return AjaxResult.success(list);
    }

}
